{% extends "smErp/base.html" %}

{% block css_style %}
    {% load staticfiles %}
    <link href="{% static 'smErp/css/brand_info.css' %}" type="text/css" rel="stylesheet">
    <link href="{% static 'smErp/assets/dropzone/basic.min.css' %}" type="text/css" rel="stylesheet">
    <link href="{% static 'smErp/assets/dropzone/dropzone.min.css' %}" type="text/css" rel="stylesheet">

{% endblock %}

{% block content %}
    <div class="inner wrp">
        <div class="page_nav">
            <a href="javascript:void(0);" class="jsUrlLink" data-url="home/index" target="_self">首页</a>
            <span class="gap">/</span>
            重置密码
        </div>

        <div class="container_box cell_layout">
            <div class="forget_box type" id="step1">
                <form class="form" id="form" novalidate="novalidate">
                    {% csrf_token %}
                    <fieldset class="frm_fieldset last">
                        <legend class="frm_legend">请输入您新设置的密码</legend>
                        <div class="frm_control_group">
                            <input id="token" name="token" class="frm_input valid" type="hidden" value="{{ token }}">
                            <input id="rp_email" name="email" class="frm_input valid" type="hidden" value="{{ email }}">
                            <input id="old_pwd" name="old_pwd" class="frm_input valid" type="hidden" value="{{ old_pwd }}">
                            <input type="password" name="pwd" style="display: none;" disabled autocomplete = "off"/>
                            <div class="frm_controls">
                                <div class="frm_inner_controls">
                                    <div class="frm_inner_controls_hd">
                                        <label class="frm_radio_label selected">
                                            <span class="lbl_content">新密码</span>
                                        </label>
                                    </div>
                                    <div class="frm_inner_controls_bd">
                                        <div class="frm_control_group">
                                            <div class="frm_controls">
                                                <span class="frm_input_box">
                                                    <input id="new_pwd" name="new_pwd" class="frm_input valid" type="password" autocomplete="new-password">
                                                </span>
                                                <p class="frm_tips">输入新的密码(密码必须包含数字、字母，区分大小写，最短8位，区分大小写)</p>
                                                <p id="passwd-msg" class="frm_tips hider"></p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="frm_inner_controls">
                                    <div class="frm_inner_controls_hd">
                                        <label class="frm_radio_label selected">
                                            <span class="lbl_content">确认新密码</span>
                                        </label>
                                    </div>
                                    <div class="frm_inner_controls_bd">
                                        <div class="frm_control_group">
                                            <div class="frm_controls">
                                                <span class="frm_input_box">
                                                    <input id="repwd" name="repwd" class="frm_input valid" type="password" autocomplete="new-password">
                                                </span>
                                                <p class="frm_tips">确认输入的新密码</p>
                                                <p id="repwd-msg" class="frm_tips hider"></p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <div class="tool_bar with_form border">
                        <a href="javascript:" class="btn btn_primary" id="okBt">确定</a>
                    </div>
                </form>
            </div>
            <div class="forget_box" style="display: none;" id="step2">
                <div class="page_msg default simple">
                    <div class="inner">
                        <span class="msg_icon_wrp"><i class="icon_msg mail"></i></span>
                        <div class="msg_content">
                            <h4>密码重置成功，请重新登录</h4>
                            <p class="spacing">
                                <a href="javascript:void(0);" class="btn btn_primary account-login">重新登录</a>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block footscript %}
    <script>
        var pass_fg ;
        var rpass_fg ;
        function ckeck_input_info(){
            if( pass_fg && rpass_fg){
                return true;
            }
            return false;
        }
        // 新密码
        $("#new_pwd").blur(function(){
            var passwd = $("#new_pwd").val();
            if(!passwd){
                $("#passwd-msg").css("color","red");
                $("#passwd-msg").html("请输入密码");
                $("#passwd-msg").show();
                pass_fg = false ;
                return;
            }else{
                // todo 密码必须是字母数字组合
                if(!check_password(passwd)){
                    $("#passwd-msg").css("color","red");
                    $("#passwd-msg").html("密码长度为8-16位,包含数字，字母的组合");
                    $("#passwd-msg").show();
                    pass_fg = false ;
                    return;
                }
            }
            pass_fg = true ;
        }).focus(function(){
               $("#passwd-msg").hide();
        });

        // 确定密码
        $("#repwd").blur(function(){
            var repwd = $("#repwd").val();
            if(!repwd){
                $("#repwd-msg").css("color","red");
                $("#repwd-msg").html("请再次输入密码");
                $("#repwd-msg").show();
                rpass_fg = false ;
                return;
            }else{
                if($("#new_pwd").val() != repwd){
                    $("#repwd-msg").css("color","red");
                    $("#repwd-msg").html("两次输入的密码不相同");
                    $("#repwd-msg").show();
                    rpass_fg = false ;
                    return;
                }
            }
            rpass_fg = true;
        }).focus(function(){
            $("#repwd-msg").hide();
        });


        // 重新填写
        $("#rewrite").on("click", function(){
            $("#emailTxt").html("");
            $("#step2").hide();
            $("#step1").show();
        });

        $("#goEmail").on("click", function(){

        });
        // 请求下发忘记密码邮件
        $("#okBt").on("click", function(){
            if(!ckeck_input_info()){
                layer.msg("输入信息有误");
                return;
            }
            var params = $("#form").serialize();
            $.ajax({
                type: 'POST',
                url: '{% url "smErp:reset_password" %}',
                data: params,
                dataType: 'json',
                success: function(data){
                    if (data.result == 0) {
                        // 成功显示成功
                        layer.msg("重置密码成功，请重新登录");
                        $("#step1").hide();
                        $("#step2").show();
                    } else {
                        //提示层
                        layer.msg(data.reason);
                    }
                }
            });
        });
    </script>
{% endblock %}




